package co.edu.usbcali.raju.games.chess.model;

import co.edu.usbcali.raju.model.Position;

public class ChessPosition implements Position {
	
	int row;
	int col;
	
	public ChessPosition() {
		super();
	}
	
	public ChessPosition(int row, int col) {
		super();
		this.row = row;
		this.col = col;
	}
	public int getRow() {
		return row;
	}
	public void setRow(int row) {
		this.row = row;
	}
	public int getCol() {
		return col;
	}
	public void setCol(int col) {
		this.col = col;
	}
	
	public String getPosition(){
		String ret=Integer.toString(8-row);
		ret+=(char)(col+67);
		return ret;
	}
	
	public int getAbsolutePosition(){
		return (row*8)+col;
	}
	
	public boolean equals(Position position){
		return (row==((ChessPosition)position).getRow()&&col==((ChessPosition)position).getCol());
	}

	@Override
	public int compareTo(Position o) {
		ChessPosition other=(ChessPosition)o;
		if(row>other.getRow()){
			return 1;
		}else{
			if (row==other.getRow()){
				if(col>other.getCol()){
					return 1;
				}else{
					if(col<other.getCol()){
						return -1;
					}else{
						return 0;
					}
				}
			}else{
				return -1;
				}
		}
	}
	
	public String toString(){
		return row+" "+col;
	}

}
